@extends('backend::layout')
@section('title',$page_title)
@push('styles')
    <link href="{{asset(config('view.plugin').'/layui/layui_ext/cascader/cascader.css')}}" rel="stylesheet">
    <link href="{{asset('assets/vendor/other/jquery.searchableSelect.css')}}" rel="stylesheet">
@endpush
@section('content')
    <div class="row">
        <div class="col-lg-12">
                @component('backend::component.form.form')
                @slot('form_title') {{$page_title}} @endslot
                @slot('formId') add-cat @endslot
                @slot('action') {{route('b_ArticleCat_addCat')}} @endslot

                    @component('backend::component.form.form-group')
                        @slot('title') 分类标识 @endslot
                        @component('backend::component.form.input')
                            @slot('name') category_name @endslot
                        @endcomponent
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 分类名称 @endslot
                        @component('backend::component.form.input')
                            @slot('name') category_title @endslot
                        @endcomponent
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 父级分类 @endslot
                        @slot('class') menu-group @endslot
                        <div class="layui-input-block">
                            @component('backend::component.form.input')
                                @slot('name') parent_id @endslot
                                @slot('value') {{$parent_id}} @endslot
                                @slot('attr')
                                     id="tree2" readonly="readonly" lay-filter="tree2"
                                @endslot
                            @endcomponent
                        </div>
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 排序 @endslot
                        @component('backend::component.form.input')
                            @slot('name') sort @endslot
                            @slot('value') 1000 @endslot
                        @endcomponent
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 描述 @endslot
                        @component('backend::component.form.textarea')
                            @slot('name') description @endslot
                        @endcomponent
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 关键词 @endslot
                        @component('backend::component.form.textarea')
                            @slot('name') key_words @endslot
                        @endcomponent
                    @endcomponent

                    @component('backend::component.form.form-group')
                        @slot('title') 设为导航 @endslot
                         <div>
                            @foreach(['1'=>'是','0'=>'否'] as $value=>$title)
                                @component('backend::component.radio')
                                    @slot('title') {{$title}} @endslot
                                    @slot('name') is_nav @endslot
                                    @slot('value') {{$value}} @endslot
                                    @if($value == 0)
                                        @slot('checked') checked @endslot
                                    @endif
                                 @endcomponent
                            @endforeach
                         </div>
                    @endcomponent

                @slot('buttons')
                    @component('backend::component.form.button')
                        @slot('title') 提交 @endslot
                        @slot('params') {"formId":"#add-cat"} @endslot
                        @slot('class') btn-min-width ajax-form @endslot
                    @endcomponent
                    @component('backend::component.form.button')
                        @slot('title') 重置 @endslot
                        @slot('type') reset @endslot
                        @slot('color') danger @endslot
                        @slot('class') btn-min-width @endslot
                    @endcomponent
                @endslot
            @endcomponent
        </div>
        <!--/.col-->
    </div>
@endsection
@push('scripts')
    <script>
        layui.use(['jquery','layer','treeSelect'], function(){
            var $ = layui.jquery;
            var layer = layui.layer;
            var treeSelect = layui.treeSelect;
            selectParent();

            function selectParent() {
                treeSelect.render({
                    // 选择器
                    elem: '#tree2',
                    // 数据
                    data: "{{route('b_ArticleCat_getParentCat')}}",
                    // 异步加载方式：get/post，默认get
                    type:'get',
                    // 占位符
                    placeholder: '请选择父级分类',
                    // 是否开启搜索功能：true/false，默认false
                    search: true,
                    // 点击回调
                    click: function(d){
                        $('#tree2').val(d.current.id);
                    },
                    success: function (d) {
                        var defaultVal = $('#tree2').val();
                        if (defaultVal>0) {
                            treeSelect.checkNode('tree2', parseInt(defaultVal));
                            $('#tree2').val(d.current.id);
                        }
                    }
                });
            }

        });
    </script>
@endpush